package org.jeecg.modules.dzswj;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import java.security.SecureRandom;

public class DESUtil {
	
	private static String DES = "DES";
	
	private static byte[] encryptOrDecrypt(boolean encrypt, byte[] desKey, byte[] data) {
        return null;
    }

	/**
	 * 返回值已做base64加密处理
	 * @param data
	 * @param desKey
	 * @return
	 * @throws Exception
	 */
    public static char[] encrypt(byte[] data, byte[] desKey) throws Exception {
        return Base64.encode(encryptOrDecrypt(true, desKey, data));
    }
    
    /**
     * 
     * @param data 传入值需做base64加密处理
     * @param desKey
     * @return
     * @throws Exception
     */
    public static byte[] decrypt(char[] data, byte[] desKey) throws Exception {
        return encryptOrDecrypt(false, desKey, Base64.decode(data));
    }

    /**
     * 返回值已做base64加密处理
     * @param data
     * @param key
     * @return
     * @throws Exception
     */
    public static String encrypt(String data, String key) throws Exception {
        return new String(Base64.encode(encryptOrDecrypt(true, key.getBytes(), data.getBytes())));
    }

    /**
     * @param data 传入值需做base64加密处理
     * @param key
     * @return
     * @throws Exception
     */
    public static String decrypt(String data, String key) throws Exception {
        return new String(encryptOrDecrypt(false, key.getBytes(), Base64.decode(data.toCharArray()))).trim();
    }
	
}
